<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>TextEditor - jQuery EasyUI</title>
	<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="texteditor.css">
	<script type="text/javascript" src="easyui/jquery.min.js"></script>
	<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>

	<script type="text/javascript">
		var componentId;
		var code;
		function requestComponent(id){
			componentId = id;
			var http = new XMLHttpRequest();
            var url = '/components/' + id;
            http.onreadystatechange = function(){
                if(http.readyState == 4 && http.status == 200){
                    var data = http.responseText;
                    var jsoncontent = JSON.parse(data)
                    props = jsoncontent['properties'];
                    for(i in props){
                    	p = props[i];
                    	if(p['name'] == 'code'){
                    		v = p['value'];
                    		code = v;
                    		$('#editor').textbox('setText', v);
                    	}
                    }
                } else {

                }
            }
            http.open("GET", url);
            http.send(null);
		}

		function save(){
			var http = new XMLHttpRequest();
            var url = '/property/' + componentId;
            http.onreadystatechange = function(){
                if(http.readyState == 4 && http.status == 200){
                    
                } else {

                }
            }
            var json = [{'name': 'code', 'value': $('#editor').textbox('getText')}]
            http.open("POST", url);
            http.setRequestHeader('content-type', 'application/json');
            http.send(JSON.stringify(json));
		}

		function main(){

		}
	</script>
</head>
<body onload = "main()">
<h1>Program Editor</h1>
<input class="easyui-textbox" id='editor' data-options="multiline:true" value="" style="width:500px;height:400px">
<button onclick="save()">Save</button>
</body>
</html>